package com.dhcc.cdc.base.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.base.entity.CdcSymptomEntity;
import com.dhcc.cdc.base.service.ICdcSymptomService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 症状体征
 * 
 * @ClassName: CdcSymptomController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:19:37
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcsymptom")
public class CdcSymptomController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcsymptom/";

	@Autowired
	private ICdcSymptomService cdcSymptomService;
	

    /**
     * 跳转到症状体征列表首页
     */
    @RequestMapping("")
    @Permission("cdcsymptom:list")
    public String index() {
        return PREFIX + "cdcsymptom.html";
    }
	
    /**
     * 跳转到新增症状体征
     */
    @RequestMapping("/to_add")
    @Permission("cdcsymptom:add")
    public String toAdd() {
        return PREFIX + "cdcsymptom_add.html";
    }
	
	/**
     * 跳转到修改症状体征
     */
    @RequestMapping("/to_update/{cdcSymptomId}")
    @Permission("cdcsymptom:update")
    public String toUpdate(@PathVariable Long cdcSymptomId, Model model) {
        CdcSymptomEntity cdcSymptom = this.cdcSymptomService.selectById(cdcSymptomId);
        model.addAttribute("cdcSymptom",cdcSymptom);
        return PREFIX + "cdcsymptom_edit.html";
    }

    /**
     * 获取症状体征列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcsymptom:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcSymptomEntity> page = new PageFactory<CdcSymptomEntity>().defaultPage();
        List<CdcSymptomEntity> result = this.cdcSymptomService.page(page,params);
        page.setRecords((List<CdcSymptomEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增症状体征
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcsymptom:add")
    @BussinessLog(value = "新增症状体征")
    public Object add(CdcSymptomEntity cdcSymptom) {
        if (CommonUtil.isOneEmpty(cdcSymptom)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcSymptom.insert();
        return R.ok();
    }

    /**
     * 删除症状体征
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcsymptom:delete")
    @BussinessLog(value = "删除症状体征")
    public Object delete(@RequestParam Long cdcSymptomId) {
	
        this.cdcSymptomService.deleteById(cdcSymptomId);

        return R.ok();
    }

    /**
     * 修改症状体征
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcsymptom:update")
    @BussinessLog(value = "修改症状体征")
    public Object update(CdcSymptomEntity cdcSymptom) {
        if (CommonUtil.isOneEmpty(cdcSymptom)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcSymptomEntity old = this.cdcSymptomService.selectById(cdcSymptom.getId());

        old.setCode(cdcSymptom.getCode());
        old.setDescription(cdcSymptom.getDescription());
        old.setVersion(cdcSymptom.getVersion());
        old.setIsChapter(cdcSymptom.getIsChapter());
        old.setIsActive(cdcSymptom.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
